package reflect;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;

public class ReflectDemo6 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");
        Method method = cls.getMethod("say", String.class, int.class);

        String name = method.getName();
        System.out.println("方法名:" + name);

        Class returnType = method.getReturnType();
        System.out.println("返回值类型:" + returnType);

        Class[] parameterTypes = method.getParameterTypes();
        System.out.println("参数类型:" + Arrays.toString(parameterTypes));

        int pc = method.getParameterCount();
        System.out.println("参数个数:" + pc);

        //获取方法的访问修饰符
        /*
            Status
            public static final int 流血=1
            public static final int 中毒=2
            public static final int 冻结=3
            public static final int 晕眩=4

            hero.status = Status.流血;

            if(hero.status==Status.流血){

            }else if(hero.status==Status.中毒){
            }
         */
        int modifiers = method.getModifiers();
        switch (modifiers) {
            case Modifier.PUBLIC:
                System.out.println("公开方法");
                break;
            case Modifier.PRIVATE:
                System.out.println("私有方法");
                break;
            case Modifier.PROTECTED:
                System.out.println("受保护方法");
                break;
        }
    }
}